import { createStore, applyMiddleware } from "redux";
import rootReducer from './store/reducers/index'
import ReactDOM from "react-dom";
import React from "react";
import App from "./App";
import logger from 'redux-logger'


//使用中间件,添加日志功能
const store = createStore(rootReducer, applyMiddleware(logger));

//中间件原理
// const  next = store.dispatch
// store.dispatch = (action)=>{
//   console.log('dispatch-改写前',action)
//   next(action)
//   console.log('dispatch-改写后')
// }

setTimeout(()=>{
  store.dispatch({type: "GETONE", payload: "username "});
},2000);

setTimeout(()=>{
  store.dispatch({type: "ADDMESSAGE", payload: [1,2,3]});
},2000);

setTimeout(()=>{
  store.dispatch({type: "CHANGESTATUS", payload: "status "});
},2000);

store.subscribe(()=>{
  console.log(store.getState())
})

ReactDOM.render(
    <App />,
    document.getElementById('root')
  );
